from django.db import models

from bolosdalu.utils.util import Util


__author__ = 'Edgard JR'


class Foto(models.Model):
    legenda = models.CharField(max_length=30, null=False, blank=False)
    imagem = models.ImageField(upload_to="img/galeria", null=False, blank=False)
    imagem_min = models.CharField(max_length=100)

    def save(self, *args, **kwargs):
        path_img_min = Util.create_small_image(self.imagem, 121, 121)

        self.imagem_min = path_img_min

        super(Foto, self).save(*args, **kwargs)


    def __unicode__(self):
        return self.legenda


    class Meta:
        app_label = 'bolosdalu'